/*
 * @Author: hruomei
 * @Title: 公共混入文件
 * @Description: 提供常用的变量混入,多语言,主题色等
 * @CreateTime: 2019/10/01
 * @LastUpDateTime: 2020/01/20
 * @Version: V1.03
*/

import {
    isNull,
    now
} from './api.js'
import { mapState } from 'vuex'

export default {
	filters: {
		nullFilter(val) {
			if(!val || val == 'null') {
				return ''
			}
			
			return val;
		},
		timeFilter(time) {
			if(isNull(time)) {
				return '';
			}
			
			let today = now();
			let targetDay = time.substring(0,10);
			
			if (today == targetDay) {
				return time.substring(11,16); // 如果是当天，则显示时分
			} else {
				return time.substring(5, 16); // 如果非当天，显示日期
			}
		},
		minuteFilter(time) {
			if(isNull(time)) {
				return '';
			}
			
			let today = now(),
				targetDay = time.substring(0,10);
				
			if (today == targetDay) {
				return time.substring(11,16); // 如果是当天，则显示时分
			} else if (today.substring(0, 4) === targetDay.substring(0, 4)) {
				return time.substring(5, 10); // 如果非当天，显示日期
			} else {
				return time.substring(0, 10); // 如果非当年，显示年月日
			}
		}
	},
	computed: {
		...mapState('lang', {
			lang: 'lang'
		}),
		...mapState('themeColor', {
			themeColor: 'themeColor'
		})
	}
};
